import {ref,reactive} from 'vue'
import { getRoleListApi } from '@/api/role'
export const useRoleTable = () => {
  // 定义表格绑定的数据
  const tableData = reactive({
    list:[]
  })

  //表格查询的参数
  const listParams = reactive({
    page:1,
    size:10,
    username:'',
    total:0,
    current:1
  })
// 查询用户列表
const getRoleList = async()=>{
  const res = await getRoleListApi(listParams)
  if(res && res.code === 200){
    console.log(res.data);
    tableData.list = res.data.page.records
    listParams.total = res.data.page.total
  }
}

 //页容量改变时触发
 const sizeChange = (size) =>{
  listParams.size = size;
  //重新加载表格
  getRoleList();
}

//页数改变时触发
const currentChange = (page) =>{
  listParams.current = page;
  //重新加载表格
  getRoleList();
}
const resetBtn = () =>{
  listParams.roleName = '';
  getRoleList();
}
// searchBtn
const searchBtn = () =>{
  //重新加载表格
  getRoleList();
}
return {
  tableData,
  listParams,
  getRoleList,
  sizeChange,
  currentChange,
  resetBtn,
  searchBtn
}
}